home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / networking / rpcdemo / rminfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.1 KB  |  87 lines

  1. /*
  2.  * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  * rminfo.c --
  19.  *
  20.  *    This is a simple RPC client program to retrieve real memory usage
  21.  *    information from a host running IRIX that has rpc.rminfod installed.
  22.  *
  23.  *    usage:  rminfo host1 [host2 ...]
  24.  */
  25.  
  26. #include <stdio.h>
  27. #include <rpc/rpc.h>
  28. #include <sys/param.h>
  29. #define _RPCGEN_CLNT
  30. #include "rminfo.h"
  31.  
  32. /*
  33.  * pprint --
  34.  *
  35.  *    Print values in terms of kilobytes or megabytes, if possible.
  36.  */
  37.  
  38. #define    MAXKBUF        20
  39. #define    kilo        1024
  40. #define    mega        (kilo*kilo)
  41.  
  42. static void
  43. pprint(char *lab, long val)
  44. {
  45.     if (val >= mega)
  46.         printf("%s%.1fM", lab, ((float)val) / mega);
  47.     else if (val >= kilo)
  48.         printf("%s%.1fK", lab, ((float)val) / kilo);
  49.     else
  50.         printf("%s%d", lab, val);
  51. }
  52.  
  53. main(int argc, char **argv)
  54. {
  55.     char    *srv;
  56.     CLIENT    *clnt;
  57.     rminfo1    *rm;
  58.  
  59.     while (argc-- > 1) {
  60.     srv = *++argv;
  61.  
  62.     /*
  63.      * Once the client handle is created, get the info from the server.
  64.      */
  65.     clnt = clnt_create(srv, RMINFOPROG, RMINFOVERS, "udp");
  66.     if (clnt == NULL) {
  67.         fprintf(stderr, "rminfo: %s", clnt_spcreateerror(srv));
  68.         continue;
  69.     }
  70.  
  71.     rm = rminfoproc_get_1(NULL, clnt);
  72.     if (rm == NULL) {
  73.         fprintf(stderr, "rminfo: %s", clnt_sperror(clnt, srv));
  74.         continue;
  75.     }
  76.     clnt_destroy(clnt);
  77.  
  78.     pprint("phys ", rm->physmem);
  79.     pprint(", buf ", rm->bufmem);
  80.     pprint(", free ", rm->freemem);
  81.     pprint(", avails ", rm->availsmem);
  82.     pprint(", availr ", rm->availrmem);
  83.     pprint(", delwri ", rm->delwri);
  84.     putchar('\n');
  85.     }
  86. }
  87.